//package ui;
//
//public class CalendarTaskPanel
//{
//
//}
package ui;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.util.Calendar;
import java.util.Date;
import java.util.ArrayList;

import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.border.MatteBorder;

import model.Task;
import ui.ItemList;

public class CalendarTaskPanel extends ItemList{

//	private CtrRenter r;
	private Date date;
	private ArrayList<Task> tasks;
	public CalendarTaskPanel(String name, int sizePctY,Date date) {
		
		super(name, sizePctY);
		this.date = date;
		
		//setTitlePanel();

		tasks = new ArrayList<Task>();
		tasks.add(new Task("Recieve apartment # 14", "Contact: Pia Andersen, tlf: 12345678", new Date(), new Date()));
		tasks.add(new Task("Show apartment # 14", "Contact: Jens Kristensen, tlf: 87654321", new Date(), new Date()));
		tasks.add(new Task("Check washing mashine apartment#12", "Contact: Anja Moller, tlf: 32165487", new Date(), new Date()));


		int count =0;
		for(Task t:tasks)
		{
			System.out.print("S: "+t.getScheduled()+"D: "+this.date);
			Calendar cal = Calendar.getInstance();
			cal.setTime(t.getScheduled());
			int dayT = cal.get(Calendar.DATE);
			int monthT = cal.get(Calendar.MONTH);
			int yearT = cal.get(Calendar.YEAR);
			
			cal.setTime(date);
			int day = cal.get(Calendar.DATE);
			int month = cal.get(Calendar.MONTH);
			int year = cal.get(Calendar.YEAR);
			
			if(dayT == day && monthT == month && yearT == year)
			{
				System.out.print("New task");
				count ++;
				newPanel(t);
			}
			
		}
		if(count == 0)
		{
			newPanel(new Task("No tasks","No tasks are scheduled on " + this.date ,new Date(), new Date()));
		}
	
	}

	@Override
	protected void setPanels(JPanel panel, Object o){
		//System.out.println("Waiting List Panels Loaded");
		//panel.setPreferredSize(new Dimension( 180 , 50 ));
		Task t = (Task)o;
		
		Font font = new Font("Segoe UI Black", Font.BOLD,11);
		Font font2 = new Font("Segoe UI Black", Font.PLAIN,10);
		
		JTextArea label1 = new JTextArea(t.getTitle());
		label1.setFont(font);
		label1.setLineWrap(true);
		label1.setBackground(new Color(0f,0f,0f,0f ));
		label1.setBorder(new MatteBorder(0, 0, 0, 0, new Color(0f,0f,0f,0f )));
		label1.setWrapStyleWord(true);
		label1.setEditable(false);
		
//		JLabel label1 = new JLabel(t.getTitle());
//		label1.setFont(font);
		
		JTextArea label2 = new JTextArea(t.getDesc());
		label2.setFont(font2);
		label2.setLineWrap(true);
		label2.setBackground(new Color(0f,0f,0f,0f ));
		label2.setBorder(new MatteBorder(0, 0, 0, 0, new Color(0f,0f,0f,0f )));
		label2.setWrapStyleWord(true);
		label2.setEditable(false);
		

		panel.add(label1,BorderLayout.CENTER);
//        panel.add(new WaitinglistButtons(Color.RED),BorderLayout.LINE_END);
        panel.add(label2,BorderLayout.PAGE_END);
        
	}
}
